public class Solution400 {

    int[] ceiling=new int[]{0,9,189,2889,38889,488889,5888889,68888889,788888889,Integer.MAX_VALUE};

    public int findNthDigit(int n) {
        int t=0;
        for (int i=0;i<ceiling.length;i++){
            if (n<=ceiling[i]){
                t=i;
                break;
            }
        }
        int m=(n-ceiling[t-1]-1)/t;
        int v=(n-ceiling[t-1]-1)%t;
        int q=(int)Math.pow(10,t-1)+m;
        String s=String.valueOf(q);
        return Integer.parseInt(String.valueOf(s.charAt(v)));
    }

    public static void main(String[] args) {
        System.out.println(new Solution400().findNthDigit(10));
    }
}
